package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.UserScore;
import com.ruoyi.system.service.IGradesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.domain.AjaxResult;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/grades")
public class GradesController extends BaseController {
    @Autowired
    private IGradesService iGradesService;
    @Autowired
    private UserScoreController userScoreController;

    //  根据用户id查询题库
    @Anonymous
    @RequestMapping("/selectablebyid/{userid}")
    private TableDataInfo selectablebyid(@PathVariable Integer userid) {
        List<Map> maps = iGradesService.selectableById(userid);
        return getDataTable(maps);
    }

    // 中层管理员查询中层的评分项目题库
    @Anonymous
    @RequestMapping("/selectmanage/{userid}")
    private TableDataInfo selectmanage(@PathVariable Integer userid) {
        List<Map> maps = iGradesService.selectmanage(userid);
        return getDataTable(maps);
    }


//    查询评分项目
//    @Anonymous
//    @RequestMapping("/selectablebyid")
//    private AjaxResult selectablebyid01(@RequestBody Map map){
//        List<Map> maps = iGradesService.selectableById01(map);
//        return new AjaxResult(1024,"trun",maps);
//    }

    //  新增评分项目
    @Anonymous
    @RequestMapping("/insertScore")
    private Integer insertables01(@RequestBody Map maps) {
        //获取当前系统时间
        LocalDate date = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        String dateTime = formatter.format(date);
        String assessdate = maps.get("assessDate").toString();
        LocalDate dateTimeLocalDate = LocalDate.parse(dateTime + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        LocalDate assessdateLocalDate = LocalDate.parse(assessdate + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        if(maps!=null){
            // 比较两个日期
            if (assessdateLocalDate.isBefore(dateTimeLocalDate)) {
                return 1;
            } else if (assessdateLocalDate.isAfter(dateTimeLocalDate)) {
                return 0;
            } else {
                return 1;
            }
        }else {
            return 2;
        }
    }
}
